home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / •New Files / HexAndSuch Folder / HexandSuch.txt < prev    next >
Text File  |  2000-01-01  |  38KB  |  602 lines

  1.       ###############################################################################
  2.       ################# ******************************************* #################
  3.       ##                                                                           ##
  4.       ##                          ---=== HEX AND SUCH ===---                       ##
  5.       ##            a beginner's guide to the Abyss of hexadecimal numbers         ##
  6.       ##                                                                           ##
  7.       ##                                 by: ProZaq                                ##
  8.       ##                                                                           ##
  9.       ################# ******************************************* #################
  10.       ###############################################################################
  11.  
  12.  
  13.  
  14. Are you a "newbie"?  As long as you're interested in not only computers but also in what's
  15. making computers work the way they do, then you'll definitely need to learn and master the
  16. meaning of a couple of basic expressions/ terms/ concepts.  Take, for example, the hexadecimal
  17. number system; it doesn't matter if you want to learn the basics of programing or if you want
  18. to write programs for Macs or PC's or you just wanna cheat on some computer games; you have to
  19. learn and master it in order to be able to "exploit" it.  And as you learn more you will
  20. notice that all these concepts are interrelated and one can be manipulated to change the
  21. other.
  22.  
  23. In this file I shall try to explain the following topics: binary and hexadecimal numbers,
  24. bytes/words/longs, ASCII characters, strings, HexEditors, the hardware components of a
  25. computer, and debuggers.  If you find that you are not familiar with an expression, then take
  26. a look in the "The Computer's Hardware Components" chapter.
  27.  
  28.  
  29. --==< Binary, Decimal, and Hexadecimal Numbers >==--
  30.  
  31. Oh boy!  Where do I start?  Well, at the very, very, very beginning...
  32. If I remember my IT classes well, the whole fame about binary numbers and calculations with
  33. binary numbers goes to an English fellow named George Boole.  He developed amongst others
  34. Boolian Algebra.  Remember all those horrible hours you had to spend in algebra class learning
  35. formulas like: a(b+c) = a*b + a*c?  Well you have him to thank for it.  He also developed a
  36. type of logic where he used ones and zeros to represent the logical flow of an operation,
  37. which is the kind of logic that every personal computer chip uses today.
  38.  
  39. You know how everyone is always saying  that computers are all about ones and zeros?  Well
  40. that's because everything in computers narrows down to being a one or a zero (an electronic
  41. current or the lack of it).
  42.  
  43. But what on earth is the binary number system?  Well, let's try to define the decimal number
  44. system first (the one we use in every day mathematics) since we're more familiar with it.
  45.  
  46. The decimal number system is based on the number 10.  Twas the name "Decimal"; which means
  47. "tenth" in Latin (doesn't "mal" mean "multiply" in German?).  You have the numbers zero
  48. through nine.  When you start counting from zero up, you hit nine.  And what happens when you
  49. hit ten?  You reset the value of the rightmost column (set it to zero), and carry a one into
  50. the next column.   At one hundred you reset the two rightmost columns and carry a one into the
  51. next one. And so on.  So as you notice you carry numbers at the powers of ten.  Like 10^1 =10
  52. (^ means raised to the power), 10^2 = 100, 10^3 = 1000, 10^4 = 10 000, 10^5 = 100 000, 10^6 =1
  53. 000 000 etc.    
  54.  
  55. Let's break the number "9876" into columns representing the numbers at which the carrying
  56. occurs.  The "thousands", "hundreds", "tens", and "ones" column.
  57.  
  58. | Thousands  |  Hundreds  |    Tens    |    Ones    |
  59. |   (10^4)   |   (10^3)   |   (10^2)   |   (10^1)   |
  60. |      9     |      8     |      7     |      6     |
  61.  
  62. As you might have noticed, in order to get the number nine thousand eight hundred and seventy
  63. six you multiply the value of each column with the appropriate multiple of ten then add the
  64. values together (9*10^4 + 8*10^3 + 7*10^2 + 6*10^1).
  65.  
  66. In the binary number system we only have two numbers to work with instead of ten as we had in
  67. decimal.  One and zero.  So this means, that instead of carrying numbers at the powers of ten
  68. we carry numbers at the powers of two; namely: 2^1 = 2, 2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32,
  69. 2^6 = 64, 2^7 = 126 and 2^8 = 256.
  70.  
  71. When dealing with binary a lot of times the value of all eight columns of numbers are shown
  72. even if it is zero.  Makes the calculations easier.  For example, one in binary has the value
  73. 1 but can also be written as 00000001.  
  74.  
  75. Here is a little chart showing the numbers one to sixteen in binary:
  76.  
  77. Value of column: 
  78.  126 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | = value of each column added up
  79.   0     0    0    0   0   0   0   0   = 0
  80.   0     0    0    0   0   0   0   1   = 1
  81.   0     0    0    0   0   0   1   0   = 2 
  82.   0     0    0    0   0   0   1   1   = 3
  83.   0     0    0    0   0   1   0   0   = 4
  84.   0     0    0    0   0   1   0   1   = 5
  85.   0     0    0    0   0   1   1   0   = 6
  86.   0     0    0    0   0   1   1   1   = 7
  87.   0     0    0    0   1   0   0   0   = 8
  88.   0     0    0    0   1   0   0   1   = 9
  89.   0     0    0    0   1   0   1   0   = 10
  90.   0     0    0    0   1   0   1   1   = 11
  91.   0     0    0    0   1   1   0   0   = 12
  92.   0     0    0    0   1   1   0   1   = 13
  93.   0     0    0    0   1   1   1   0   = 14
  94.   0     0    0    0   1   1   1   1   = 15
  95.   0     0    0    1   0   0   0   0   = 16
  96.  
  97. Here's an other approach in trying to explain how binary works.  Try adding up the values of
  98. the columns where there is a one.  In ten for example (00001010) there is a one in the two's
  99. and the eight's column.  Thus when these values are added together (two plus eight) we get
  100. ten.  The same goes for fifteen, there's a one in each column so, eight plus four, plus two,
  101. plus one equals fifteen.
  102.  
  103. OK, now we've reached the hexadecimal numbers.  Well, for these suckers we carry at powers of
  104. sixteen.  With other words we count from zero to fifteen before reseting the first column and
  105. increasing the next.  The slight problem of only having ten numbers in our everyday number
  106. system is compensated by using six alphabetical letters to represent the numbers ten through
  107. fifteen.  Thus the numbers used in the hexadecimal number system have the following notation:
  108. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
  109.  
  110. Once fifteen is reached, the next number (as always) is represented by reseting the first
  111. column and increasing the next.  Meaning that sixteen in hex is "10".
  112.  
  113. If you have managed to get this far you've done a good job.  And if you still have
  114. difficulties understanding what the different number systems are all about then I'll let you
  115. in on a big secret.  Only a very few people convert between number systems in their head. 
  116. Most of us mortals rely on something called the "Scientific calculator".   This makes life a
  117. lot simpler!  I always use a calculator simply
  118. because it's just so much faster.  I believe that if you know the principles behind the
  119. different number systems and you have access to a calculator that converts between these then
  120. you're set.
  121.  
  122. So now you know what different number systems are.  But when it comes to writing them down
  123. some difficulties may arise.  It's obviously easy to distinguish numbers represented in
  124. binary.  Just to be on the safe side, however, it's a convention to put a "%" sign in front of
  125. binary numbers.  On the other hand "123" can be a number represented in both hex and decimal
  126. form.  If it's a decimal number it's simply one hundred twenty three.  But if it's a
  127. hexadecimal number then it has the decimal value of 291, two hundred ninety one.  Big
  128. difference there!  So how do you distinguish between hex and decimal numbers?  Well the most
  129. common way is to represent hex numbers by putting a dollar sign, "$" in front of the number. 
  130. In the programing language C you represent decimal numbers using the "0x" prefix.  In assembly
  131. language it is common practice to use the "#" sign when representing decimal numbers.  I tend
  132. to be very lazy so when I want to represent decimal numbers I just don't bother using any
  133. signs, but for hex numbers I always use the "$" sign.  For example: #12345 (decimal) is $3039
  134. (hexadecimal);  and $ABCDEF (hexadecimal) is 11259375 (still decimal if no sign is used).  
  135. Through the course of this file I will use this method of notation.  I might, however, refer
  136. to hexadecimal numbers without the $ sign if I think that it's obvious what I mean.
  137.  
  138.  
  139. --==< Bytes, words, and longs >==--
  140.  
  141. Now that you know what hex is, there is a need to discuss the length of a number.  The length
  142. of numbers have a large part when it comes to writing programs.  By using numbers with
  143. different lengths the programmer can manipulate data much more easily.  Another benefit of
  144. numbers with different lengths is that a small numbers will occupy a small place in the memory
  145. instead of occupying an unnecessarily large one.  This is not much of a problem
  146. now with the increase of of both RAM and HardDisk sizes, but back in the days of C-64's and
  147. before, when programmers only had so much RAM to work with, it was very important wether a
  148. number took up 1 or 4 bytes.
  149.  
  150. Anyway, in assembly language for the 68k Macintosh processors we talk about bytes, words and
  151. longs.  A byte is two digits long and is between 00 and FF (0 to 255 in dec).  A word is 4
  152. digits long and is between 00 00 and FF FF (0 to 65535 in dec).  Finally a long is made up of
  153. 8 digits and is 
  154. between 00 00 00 00 and FF FF FF FF (0 to 4294967295 dec).  
  155.  
  156. With other words:
  157.  
  158. byte:      $00              - $FF                   #0 - #255
  159. word:      $00 00           - $FF FF                #0 - #65535
  160. long:      $00 00 00 00     - $FF FF FF FF          #0 - #4294967295
  161.  
  162. As you can see a byte takes up one fourth of the memory a long does.  This principle will be
  163. discussed further in the chapter dealing with HexEditors.  I think it might be a good thing
  164. for you to learn how many digits a byte, a word and a long has.  I will use these expressions
  165. later on.  I chose to use these expressions (and not including floats and doubles) because I
  166. feel that even an experienced person can get far with only these three length-notations.
  167.  
  168. For those interested, the programing language C uses the following expressions to refer to the
  169. length of numbers:
  170.  
  171. char                c = 'A';  // 1-byte long by definition (in C++).
  172. short int           si= 1;    // minimum range +/-32767.
  173. short               s = 2;    // short same as short int.
  174. int                 i = 3;    // minimum range +/-32767.
  175. long int            li= 4;    // minimum range +/-2147483647.
  176. long                l = 5;    // long same as long int.
  177. float               f = 10.1; // min 6 digits (decimal) precision.
  178. double              d = 11.2; // min 10 digits (decimal) precision.
  179. long double         ld= 12.3;
  180.  
  181. unsigned char       uc;       // unsigned integers can only store
  182. unsigned short int  usi;      // positive numbers.
  183. unsigned int        ui;
  184. unsigned long int   uli;
  185.  
  186. signed char         sc;       // signed integers can store positive
  187. signed short int    ssi;      // or negative numbers.
  188. signed int          si2;
  189. signed long int     sli;
  190. (Information taken from "C Reference Card" by Argus Software Engineering)
  191.  
  192.  
  193. --==< ASCII Characters >==--
  194.  
  195. With the arrival of networks reaching from one country to the other arose the problem of
  196. character mapping.  When you push the letter "a" on your keyboard, the hardware components of
  197. the computer send a number value to the processor which represents the letter "a".  But how on
  198. earth would a computer in Yugoslavia, configured to deal with the Yugoslavian alphabet, be
  199. able to interpret letter "ä" which is fairly common in the Swedish language.  To eliminate the
  200. problem a new standard for keyboards, the American Standard Code for Information Interchange
  201. (ASCII) was adopted in most places.  What this means is that (in theory at least) all
  202. alphabetical characters will appear the same way no matter where you are in the world. 
  203. Unfortunately this only works in theory, since different keyboards have different mapping of
  204. different keys and have different ways of showing different letters etc...  The good news is
  205. that just like you didn't have to know how to convert hex numbers in your head, it's enough
  206. that you know that ASCII refers to the numerical values of the different characters on your
  207. keyboard that the computer can interpret as such. 
  208.  
  209. Now you know that when you push a key on the keyboard, the corresponding number value is sent
  210. to the processor (well in reality it's interpreted by the OS and sent to the active
  211. application).  So, what is this number value?  Well, every character on the keyboard is
  212. represented by a different number.  For example the English lowercase alphabetical characters
  213. range from $61 to $7A (a-z).  Notice that when it comes to computers there's a define
  214. difference between lowercase and uppercase letters.  Thus the uppercase English letters are
  215. represented by the numbers $41 to $5A (A-Z). 
  216.  
  217. It is important to realize that every ASCII character (every character on the keyboard) can be
  218. represented by a number that's the size of a byte.  Meaning a number between 1-255, $1-FF. 
  219. Thus the current standard of keyboard maps can only handle 255 characters.  
  220.  
  221. But that's of no real importance either.  The most common ASCII characters and their values in
  222. both hex and decimal form are available in the included file "ASCII.txt"
  223.  
  224. Now then, we know that ASCII characters are represented by numbers.  For example the capital
  225. letter "A" is represented by 65 ($41).  "B" is 66 ($42) and "C" is 67 ($43).  So the letters
  226. "ABC" could be represented by the ASCII values 65 66 67 (or in hex 41 42 43).  And this brings
  227. us to our next topic, strings.
  228.  
  229.  
  230. --==< Strings >==--
  231.  
  232. The expression "string" refers to a sequence of keyboard characters.  For example "Hello
  233. world!" would be a string.  Notice that the computer doesn't care about the space between the
  234. two words, it looks upon the sentence as only one string of characters.  This leads to the
  235. problem of representing strings.  Imagine how a string would look like in the computer's point
  236. of view.  It would be a sequence of numbers stored somewhere in the memory.  And unless you
  237. inform the computer how to interpret the beginning or end of the string, it will not know
  238. where the string ends.  
  239.  
  240. There are currently two standard ways of representing strings.  The C way and the Pascal way. 
  241. I'll start with the C way, it's easier.  Basically after the last character in the string
  242. there is a zero-byte.  This means that a value of zero marks  the end of the string.  For
  243. example:
  244.  
  245.   H     E     L     L     O     _     W     O     R     L     D     !    •    
  246.  72    69    76    76    79    95    87    79    82    76    68    33   00
  247. $48   $45   $4c   $4c   $4f   $5f   $57   $4f   $52   $4c   $44   $21  $00
  248.  
  249. Keeping in mind that the size of an ASCII character is that of a byte (max 255)  we notice
  250. that using the C method the length of the string is actual increased by one byte; the
  251. zero-byte on the end.  When a program is in need of using the above string, it needs to know 
  252. the memory address of the first character, and it knows that it has hit the end of the string
  253. when the value of the character is zero.  
  254.  
  255. The Pascal method is a bit different.  It stores the number of characters in the string as the
  256. first byte.  The example above would be portrayed like this in Pascal notation:
  257.  
  258.      •     H     E     L     L     O     _     W     O     R     L     D     !               
  259.     12    72    69    76    76    79    95    87    79    82    76    68    33 
  260.    $0c   $48   $45   $4c   $4c   $4f   $5f   $57   $4f   $52   $4c   $44   $21  
  261.  
  262. As you might have noticed there are 12 characters in the string (including the "_" and the "!"
  263. signs).  So using the Pascal method, the program would read the first byte of the string and
  264. thus determine the lenght of it.
  265.  
  266. This whole concept will be developed further in the next chapter.
  267.  
  268.  
  269. --==< Hex Editors >==--
  270.  
  271. NOTICE: When dealing with hex editors you are going to be changing real files on your
  272. computer.  By changing just one byte in a file you can corrupt it to the extent that it will
  273. not be usable any more!  So always make sure that you are working on a BACKUP of the file. 
  274. The easiest thing to do is to create a folder where you copy all the files that you want to
  275. change with the HexEditor.
  276.  
  277. Remember how all data processed by the computer is made up of a one or a zero?  Well, the same
  278. principle holds true for files stored on the hard disk, on a floppy disk, on a CD-ROM, or on
  279. any other storage media.  But because hexadecimal numbers are easier to deal with than binary
  280. numbers, we have programs that can read the content of any storage media as pure hexadecimal
  281. data.  These programs are called HexEditors.  Using the above idea, any file containing data
  282. that is stored on a media can be opened and it's contents will be represented as hexadecimal
  283. numbers.  And it does not matter whether the file is an application program or just a simple
  284. text file, since ALL files are at their "lowest level" made up of binary numbers and can thus
  285. be viewed by a HexEditor.  
  286.  
  287. The first thing you have to do is to find yourself a HexEditing program.  It doesn't matter
  288. which computer platform you have.  HexEditors exists for PC's, Mac's, Unix's, even C-64's. 
  289. Once you've found a HexEditor open up any backup file with the program.  I have a Mac and I
  290. use HexEdit 1.0.7, a freeware program by Jim Bumgardner.  If I open an application file I get
  291. something like this:
  292.  
  293. (See the picture "HexEdit.jpg")
  294.  
  295. Please note that you WILL get something completely different, since the chances of us opening
  296. the same file is very slim, and different HexEditors present the information in different
  297. ways.
  298.  
  299. Let me explain the above picture.  To the left you have the Offset column.  "Offset" refers to
  300. the distance of a data from the first byte in the file.  Since the offset here starts at zero
  301. we know that we are dealing with the beginning of the file.  Also notice that the offsets are
  302. displayed as hex values.  A good HexEditor should be able to display the offset as decimal
  303. numbers as well. 
  304.  
  305. In the middle you have the Hex column.  This is where all the hexadecimal data can be found. 
  306. If you converted all these numbers to binary, you'd have a representation of the binary
  307. information of the file as you would find it on the Hard Drive.
  308.  
  309. Finally on the right side is the ASCII column.  This is an ASCII representation of the Hex
  310. values.  This means that each hex number is looked up on an ASCII table and it's ASCII value
  311. is displayed in this column.
  312.  
  313. OK, now what?  Well, as an example I'll describe the use of HexEditors as a way to cheat on
  314. computer games.  
  315.  
  316. Off course you can not use a HexEditor to cheat on a game while you are playing it.  Those
  317. situations will be dealt with in the next chapter.  What you can do with a HexEditor, however,
  318. is to change saved games.  I mean, think about it.  What is the program actually doing when it
  319. is saving a game?  It saves all the data about the game to a file.  Like where you are
  320. positioned on the map, what items you carry, how many monsters are gonna attack you etc...  In
  321. this example I will use Realmz, a shareware game for the MacOS.  
  322.  
  323. The first thing you have to do is to find where on the HardDrive the game saves it's files. 
  324. Some games allow you to save wherever you want, while others will only allow you to save into
  325. a certain set of game folders (usually 1-10 or something like that).  So search through the
  326. game's folders (directories as they are also called), and look for a file that has the same
  327. name as your saved game. 
  328.  
  329. The next step is to find the document in which the game stores the information you want to
  330. change.  For example Realmz is a Dungeons & Dragons game for the Mac where you can create your
  331. own characters.  The attributes of the characters, such as it's strength or stamina,  are
  332. saved in a file that has the same name as the character.  
  333.  
  334. Let us presume that I have a character called Pro.  His attributes are stored in the file
  335. called "Pro".  I want to change my character's strength.  I want to make him stronger so that
  336. he can cause more damage with each hit.  The first thing I would do is to run the game and see
  337. how strong he is at that particular time.  This will be the value that the game stores in the
  338. "Pro" file.  He has a strength  of 105.  So I convert this number to hex, which gives me $69. 
  339. And then I set out to look for the hex byte $69 in the saved file.  To make things easier I
  340. look for the hex word "00 69" since the possibility of the string "00 69" appearing several
  341. times in the file is smaller than that of the string "69".  (Read "Note on HexEditors and
  342. numbers" for more information regarding this.)  When I've found this value I change it to
  343. whatever I want it to be and then I save my work.  
  344.  
  345. The problem might arise that "00 69" appears in more than one places in the file.  The easiest
  346. (and most dangerous way) is to change all the values to the value you want.  By doing this,
  347. however, you might have changed values which are very important to the program and might cause
  348. it to freeze.  By using a trial end error method you can try to change a different value every
  349. time and see if the value you changed was the correct one.  The most effective method,
  350. however, is to look at "00 69" in a context.  Meaning, look at the other numbers around it. 
  351. For instance, if you recognize the number after "00 69" as the movement points of the
  352. character then there's a good chance that you're on the right track.
  353.  
  354. Note for Macintosh users:  The MacOS divides up a file into two parts, the data fork and the
  355. resource fork.  Without getting too much into programing, here's what the purpose of these two
  356. forks are.  The resource fork should contain information such as how a window looks like,
  357. where it is located, how the menus look like etc.  With other words information used by the
  358. Operating System.  The data fork should be used to store the information used by the user's. 
  359. For example, in a word processor file the resource fork might contain information regarding
  360. the size of the window, while the data fork might contain the actual text written by the user. 
  361. However, the programmer is not obliged to follow these criterias.  They are only suggestions
  362. made by Apple.  So, when you are looking at a file with a HexEditor on a Mac, be sure to check
  363. both forks of the file for the information you are looking for.
  364.  
  365.  
  366. --==< Note On HexEditors And Numbers >==--
  367.  
  368. I find it appropriate to give a bit of a revision of numbers and strings.  
  369. To use the example from above, let's presume that my character had the strength of $69.  What
  370. we don't know is how the program stores this number.  It might store it as a byte, a word, or
  371. a long (see chapter about bytes, words and longs for more info about this).  Using common
  372. sense, if my character has a strength of $69 and is considered very very strong than the
  373. program will probably save the value as a byte or a word.  It's completely useless for it to
  374. store it as a long (although it might happen).  If, however, we regard the characters
  375. experience point, its obvious that it is a lot larger than the range of a word, so it HAS to
  376. be stored in a long (or something larger).   So instead of searching for "ABCDE" you can
  377. search for "00 0A BC DE" which should narrow down the number of occurrences of that number.
  378.  
  379. Another thing that needs to be discussed is that the length of a number has to be even.  A
  380. programmer deals with blocks (units) of memory.  The program then reserves these blocks
  381. once it's launched.  The smallest block a programmer deals with is a byte.  This means that no
  382. matter how much the programmer wants it, he/she can never store the number "1" just like that. 
  383. If it is to be stored in the memory it will be stored as "01".  However, if the programmer
  384. assigned the number to be a word it will be stored as "00 01".  And if it was assigned to be a
  385. long it will be stored as "00 00 00 01".  The computer doesn't care what number is stored in
  386. the variable.  It only cares about the length of the variable.  Thus if the computer stores
  387. three longs with the values $1, $22 and $333 respectively then it will look like this once you
  388. open the file with a HexEditor:
  389.  
  390. 00 00 00 01 00 00 00 22 00 00 03 33
  391.  
  392. Lets say you want to change the $333 part to $433.  A good HexEditor might allow you to search
  393. for "333" but remember that the smallest unit is a byte.  When you are changing "00 00 03 33"
  394. to "00 00 04 33" it's pointless to change all 8 digits.  It's enough if you change the 3'rd
  395. byte ("03" to "04").  Notice, however, that you can't just change 3 to 4.  You have to change
  396. "03" to "04".  A good HexEditor should actually not allow you to change one digit at a time. 
  397. It should require you to change one byte, 2 digits, at a time.  If you are confused then
  398. re-read this chapter, and the previous chapter dealing with lengths of numbers.  This is
  399. important stuff, and it's very important that you know it well!
  400.  
  401.  
  402. --==< The Computer's Hardware Components >==--
  403.  
  404. Now we have covered a lot of track.  You should know what the different number systems are,
  405. you should have an understanding of different programing expressions and you should know how
  406. to use a HexEditor.  In order to understand how a Debugger works, however, we need to dive
  407. into the hardware components of a computer.  Do not worry, I will keep it simple.  I will only
  408. talk about the most important parts of the computer.  As a matter of fact you will most likely
  409. recognize and already know the function of some of these components.
  410.  
  411. - The Motherboard - This is that green board within your computer covered with circuits where
  412. all the hardware is placed.  Everything from the diskdrive to the microphone is somehow
  413. connected to the Motherboard.
  414. - Memory - The part of the computer where data is stored.
  415. - RAM (Random Access Memory) - This is the temporary storage facility of the computer.  It
  416. is loaded full with information when you turn on the computer and it is emptied when you turn
  417. your computer off.  
  418. - PRAM (Parameter RAM) - Very much like ordinary RAM with the exception that there is a
  419. special battery in the computer providing the PRAM with enough electricity to keep the
  420. information in it even when the rest of the computer is turned off.  
  421. - ROM (Read Only Memory) - This is a storage unit where information can only be read from. 
  422. With other words the computer can read anything in the ROM but it can not change anything
  423. there.  Thus the ROM usually stores all the information the computer needs to be able to start
  424. when you press the "On" button.  When you think about it, a compact disk (CD) is also a
  425. read-only unit.  The computer can read the information on it, but it can't store stuff on it. 
  426. Thus the name CD-ROM.
  427. - Storage Media - For example, the HardDrive, a floppy disk, a Zip disk, etc.  These
  428. are accessories to the computer on which information is stored "indefinitely".  That is
  429. "indefinitely" in the sense that the information will still be there, even when the computer
  430. off.  This does, however, not keep the computer from replacing the information on the media. 
  431. So it can freely read from it and write to it.  It can even replace existing data with new
  432. data.
  433. - The Processor - This is the brain of the computer.  All data is sent to be calculated in the
  434. processor.  
  435. - Registers - These are blocks of memory within the processor where data is stored for a brief
  436. period of time, waiting to be processed.
  437. - Busses - Circuits, on the motherboard, where the information travels from one component of
  438. the motherboard to the other.
  439. - The Sound Card - This is like a small mother board with it's own processor, busses and
  440. registers capable of converting binary information to sound waves.
  441. - The Graphics Card - Same as the sound card except it displays information as the graphics on
  442. the monitor.
  443.  
  444. And that's all you need to know for now.
  445.  
  446.  
  447. --==< Debuggers >==--
  448.  
  449. I gave this whole chapter a lot of thought and decided on the following.  I will only give a
  450. general description of a debugger, and some theoretical uses for it.  There are a lot of
  451. different debuggers out there, for all computer platforms.  I use a Macalong with Apple's own
  452. free debugger called MacsBug.  For those interested I have included a file called "MacsBug".  
  453. I wrote this file a while back and it is not designed to be read by beginners.  However, some
  454. people might find it handy.  There are a quite a lot of other files dealing with MacsBug that
  455. might be a lot more useful.  So if you are really interested, read a few of those as well!  
  456.  
  457. A debugger is a program that allows you to take control of the complete computer.  This is
  458. done, by "stoping" the processor.  When you activate a debugger, it stops the processor from
  459. executing any commands of the program that is running at the moment.  The whole concept of a
  460. debugger is to help software developers look for mistakes in their programs or to see if it
  461. executes in a proper way.   
  462.  
  463. As you may know, when a program is launched, the Operating System loads the program from the
  464. HardDrive to the RAM.  This is done because the RAM is a lot faster than the HardDrive and
  465. most other storage medias.  Then the processor jumps to the part of the RAM where the code of
  466. the program is stored, and it starts executing each of the commands.  So, when the debugger is
  467. started the processor stops executing these commands.  It then allows the user to check the
  468. values of the certain hardware components.  This way the user can detect any mistakes in the
  469. program or just check the current state of the hardware components.  The user can even step
  470. through the code of the program.  This means that they can look at each command that makes up
  471. the program and see what it does.  As I said before, debuggers are largely used by programmers
  472. trying to figure out why their program won't work properly.
  473.  
  474. For you, the main advantage of a debugger will be that it allows you to change the data in
  475. most hardware components, including the RAM.  Since the program is loaded into the RAM when
  476. launched, and it does all the calculations in the RAM all the data/variables/information it
  477. may use will most likely be stored somewhere in the RAM.  Thus the debugger can be used to
  478. change any of these.
  479.  
  480. Since this file has had a general undertone of being an aid for cheating on computer games I
  481. decided to include a way to use MacsBug to cheat on games while you are actually playing them. 
  482. I will first summarize the theory and then go into the specifics.  In order for you to be able
  483. to follow it through you will have to know at least the basic commands and functions of
  484. MacsBug.  If you are using a different debugger, then the theory will most likely be the same
  485. but the commands will be different.
  486.  
  487. WARNING:  When you are changing memory contents or changing anything in a debugger for that
  488. matter, you CAN cause very large damages to your computer!  The incorrect use of a debugger
  489. can cause the computer to freeze and cause information to be lost!  Several other damages can
  490. also occur.  Thus I advise you to become familiar with your debugger before you attempt to
  491. change anything with it.  Read any related files, read the manuals and do some minor
  492. experimenting before you try to change stuff directly in the memory! 
  493.  
  494. So first, the theory.  I launch the game as a start.  By opening up any saved games, I force
  495. the game to load anything it might have saved on the HardDrive (and that is of use to me) to
  496. the RAM.  Then I stop the game by starting the debugger, I find where in the RAM the game is
  497. stored, I find the information I want to change and then I change it.
  498.  
  499. OK, and now for practice:
  500.  
  501. Here's the scenario:  I'm playing Heroes of Might & Magic II and I want more creatures in my
  502. armies.  I open up the hero's preference window and see that my hero has 25 Minotaurs, 53
  503. Dwarfs, 32 Griffins, 9 Skeletons and 2 Dragons.  Thus I know that the computer keeps track of
  504. how many creatures I have and that means that the number of creatures must be stored somewhere
  505. in the RAM.   
  506.  
  507. The first thing I have to do is to find out where in the RAM the game is located.  The first
  508. step is to drop into MB (this is done by holding down the apple key and pressing the power
  509. button on the keyboard).  
  510.  
  511. The second step is to issue the "hz" (heap zone) command that lists all the currently active
  512. applications and their locations in the RAM.  I got this:
  513.  
  514.  Heap zones
  515.   #1  Mod        7206K  00002800 to 0070C34F  SysZone^
  516.   #2  Mod           6K    00008D60 to 0000A88F  ROM read-only zone
  517.   #3  Mod          48K    001301F0 to 0013C1EF
  518.   #4  Mod         128K    004475B0 to 004675AF
  519.   #5  Mod       29560K  0070C350 to 023EA69F  Process Manager zone
  520.   #6  Mod        9737K    010A6830 to 01A28EFF  “Heroes II”     ApplZone^  TheZone^  Targ
  521.  
  522. As you can see Heroes II starts at memory location 010A6830 and ends at 01A28EFF (all in hex
  523. of course).  
  524.  
  525. The next step is to use the "find" command and find the number of creatures that make up my
  526. army.  See, it is very likely that a game stores relevant data close to each other.  So I
  527. presume that the program stores the number of creatures I have, in a specific block of memory
  528. in the RAM.  If I can find this block of memory, I will be able to change it's content, thus
  529. changing the number of creatures.   In some ways it's like finding information with a
  530. HexEditor.  Except you're looking for data in the RAM and not in a file.
  531.   
  532. In order to be able to use the "find" command I have to be able tell the following things: the
  533. start of the memory address, how many bytes the debuggers should search for, and what to
  534. search for.  Unfortunately I don't have all the criteria.  I have to find out how many bytes
  535. Heroes II occupies.  This can easily be done by subtracting $010A6830 from $01A28EFF.  This
  536. subtraction gives me $009826CF.  If you want you can do this calculation directly in MB, just
  537. type "01A28EFF-009826CF".  Now I have all the stuff I need to use the find command.  
  538.  
  539. In this example I issue "f 010A6830 009826CF 00190035"
  540.  
  541. The "f" stands for "find". This tells MB to use the find command.  
  542. "010A6830" is the address of the memory where Heroes II starts.  
  543. "009826CF" stands for the number bytes Heroes II occupies in the memory. It tells MB the
  544. number of bytes I want to search for, from the initial address.  
  545. "00190035" stands for 25 Minotaurs and 53 Dwarfs.  #25=$19 and #53=$35.  Since I've done this
  546. before I know that Heroes II stores the the number of creatures in word sized blocks of
  547. memory.  If I didn't know that I would have had to search for "0019" first (or "19") and look
  548. at it in it's context.  When I issued the find command I got this:
  549.  
  550. Searching for 00190035 from 010A6830 to 01A28EFE
  551.   0118EE3E  0019 0035 0020 0009  0002 0000 0003 0100  •••5•••••••••••
  552.  
  553. The first hex long represents an address in the memory.  The following four longs (16 bytes)
  554. are the values of the data contained in the RAM starting from that address.  The following 16
  555. characters are the ASCII representations of these values.
  556.  
  557. Now, if I convert the first five words to decimal numbers I get: 25, 53, 32, 9 and 2.  That's
  558. a perfect match of the number of creature I have in my army.  Thus there is a fairly good
  559. chance that HeroesII keeps track of my army starting at address 0118EE3E.  When you are doing
  560. something like this on your own and you don't think that this is the location of the memory
  561. that you are looking for, you can continue searching by hitting return until you get a message
  562. saying that it could not be found.
  563.  
  564. Then comes the dangerous part, I have to change the value in the memory.  I issue the
  565. following command, "sw 0118EE3E 00ff" (sw stands for set word).  This changed the word at the
  566. memory address 0118EE3E from "0019" to "00ff".  If I now issue the "dm 0118EE3E" command (dm
  567. stands for display memory) I see that the value at address 0118EE3E has changed to:
  568.  
  569.   0118EE3E  00FF 0035 0020 0009  0002 0000 0003 0100  •••5•••••••••••
  570.  
  571. So I return to the game by issuing the "g" command.  Apparently nothing has changed.  But if I
  572. close the preferences window and force the game to actually check how many Minotaurs my army
  573. has (by checking the variable stored in the RAM), then I can see that the game in fact thinks
  574. that I have 255 Minotaurs!  Cheat accomplished.  Now I just have to repeat the above
  575. procedures for all the other creatures.
  576.  
  577. NOTE: when you are changing the contents of the memory, make sure that you use the appropriate
  578. addresses, meaning the ones you get when you issue "hz" and the find command.  Do NOT use the
  579. memory addresses I used!  They are purely examples and WILL NOT work on your computer!
  580.  
  581.  
  582.  
  583. --==< End Notes >==--
  584.  
  585. In conclusion I hope to have given an insight to how different principles of computer
  586. technology work.  I'd like to point out to some more advanced readers that I am aware of the
  587. fact that I have generalized and simplified some concepts.  I did this only when I felt that
  588. the theory was more important than a detailed explanation.  I also hope to have made some of
  589. you interested in learning about programing and more advanced topics of IT and computer
  590. technology.  If you have any questions or comments you can reach me at prozaq@usa.net.
  591.  
  592.  
  593.  
  594. Good luck
  595.  
  596. ProZaq
  597. 1999.12.31 
  598.  
  599. Werd to mSEC, and everyone else who's ever helped me out!  It's people like you who make it
  600. worthwhile!
  601.  
  602.